import React from 'react';
import Component from '../../../common/Component';
import './index.less';

export interface PrintProps{
    width?: string,
    height?: string, // unit inch
    marginTB?: string,
    marginLR?: string,
    children?:any
}


export default class Print extends Component<PrintProps>{
    render(){
        return <div className='widge-print'> 
            {this.props.children}
        </div>
    }

    /**
     * 当mount后，插入一个style结点
     */
    componentDidMount(): void {
        let style = document.createElement("style");
        let width = this.props.width || '210mm';
        let heigth = this.props.height || "297mm";
        let marginTB = this.props.marginTB || "2.54cm";
        let marginLR = this.props.marginLR || "3.18cm";
        style.innerText = `
            @media print {
                @page {
                    size:${width} ${heigth};
                    margin:${marginTB} ${marginLR};
                }
            }
        `
        document.body.appendChild(style);
    }
}

